package com.kd.enums.product;

/**
 * 腿布局枚举（对应二面叉产品）
 * 数据库字段：leglayout TINYINT COMMENT '0-无 1-三条 2-四条(仅二面叉)'
 */
public enum LegLayoutEnum {
    NONE(0, "无"),
    THREE_LEGS(1, "三条"),
    FOUR_LEGS(2, "四条");

    private final int code;
    private final String desc;

    LegLayoutEnum(int code, String desc) {
        this.code  = code;
        this.desc  = desc;
    }

    public int getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public static LegLayoutEnum getByCode(Integer code) {
        if (code == null) return null;

        for (LegLayoutEnum value : values()) {
            if (value.code  == code) {
                return value;
            }
        }
        throw new IllegalArgumentException("无效的腿布局代码: " + code);
    }

    // 二面叉专用校验
    public static boolean isValidForSideFork(Integer code) {
        return code == null ||
                code == NONE.code  ||
                code == THREE_LEGS.code  ||
                code == FOUR_LEGS.code;
    }
}